//
//  BPComboViewController.m
//  BabyPhotograph
//
//  Created by cesh on 2017/1/5.
//  Copyright © 2017年 cesh. All rights reserved.
//

#import "BPComboViewController.h"
#import "ImageViewPlayer.h"
#import "BPComboDetailView.h"
#import "BPPayViewController.h"
#import "BPPhotographerTableViewCell.h"
#import "UIBarButtonItem+Extensions.h"
#import "BPPhotographerViewController.h"
#import "BPCommentViewController.h"
#import "BPTimeChooseView.h"
#import "BPPreviewViewController.h"
#import "UILabel+BPBoundingRect.h"
#import <UIImageView+WebCache.h>

@interface BPComboViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, BPTimeChooseViewProtocol, XLPhotoBrowserDatasource, PhotographerProtocol>

@property (strong, nonatomic) UIScrollView *scrollV;
@property (assign, nonatomic) NSInteger photographerCount;

@property (strong, nonatomic) UIView *selectedDateCell;

@property (strong, nonatomic) UITableView *photographerTableView;

@property (strong, nonatomic) BPTimeChooseView *innerLeftView;
@property (strong, nonatomic) BPTimeChooseView *innerMidView;
@property (strong, nonatomic) BPTimeChooseView *innerRightView;

@property (strong, nonatomic) UILabel *leftLabel;
@property (strong, nonatomic) UILabel *midLabel;
@property (strong, nonatomic) UILabel *rightLabel;

@property (strong, nonatomic) NSString *selectedDate;
@property (assign, nonatomic) NSInteger selectedDateIndex;
@property (strong, nonatomic) NSString *selectedTime;
@property (assign, nonatomic) NSInteger selectedTimeIndex;

@property (assign, nonatomic) NSInteger picCount;

@property (strong, nonatomic) BPPhotographerTableViewCell *selectedPhotographerCell;
@property (strong, nonatomic) NSMutableArray *chooseBtns;

@property (strong, nonatomic) NSMutableArray *photographerCellHeight;

@property (strong, nonatomic) NSDictionary *data;
@property (strong, nonatomic) NSDictionary *generalComment;
@property (strong, nonatomic) NSArray *photographerTimes;

@property (strong, nonatomic) NSArray *comments;

@property (strong, nonatomic) NSMutableArray *picViews;

@property (strong, nonatomic) NSString *photographer_id;
@property (strong, nonatomic) NSString *time_id;

@end

@implementation BPComboViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.title = @"套餐详情";
    self.navigationController.navigationBar.hidden = YES;
}

- (void)getData {
    
    [SVProgressHUD showInfoWithStatus:@"读取中"];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                     @"text/html",
                                                     @"image/jpeg",
                                                     @"image/png",
                                                     @"application/octet-stream",
                                                     @"text/json",
                                                     nil];
    
    [mgr POST:[NSString stringWithFormat:@"%@?c=Package&&a=info",requestURL]
   parameters:@{@"packageID" : self.comboID}
     progress:^(NSProgress * _Nonnull uploadProgress) {}
      success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
          if ([responseObject[@"state"] isEqualToString:@"SUCCESS"]) {
              self.data = responseObject[@"data"];
              [SVProgressHUD dismiss];
              NSLog(@"套餐详情 %@",self.data);
              //获取摄影师人数
              NSArray *photographers = self.data[@"photographers"];
              self.photographerCount = photographers.count;
              //获取总评价
              NSDictionary *generalComment = self.data[@"evaluateInfo"];
              self.generalComment = generalComment;
              
              //将cell高度初始化为80
              for (NSInteger i = 0; i < self.photographerCount; i++) {
                  [self.photographerCellHeight addObject:@(80)];
              }
              //设置最外层scrollView
              [self setupContentScrollView];
              //设置顶部的图片轮播器
              [self setupTopImagePlayer];
              //设置顶部返回键和分享按钮
              [self setupTopBackShareBtns];
              //设置价格和详情的View
              [self setupPriceView];
              //设置摄影师模块
              [self setupPhotographerView];
              //设置底部悬浮的支付view
              [self setupBottomPayView];
              //获取评论
              AFHTTPSessionManager *mgr2 = [AFHTTPSessionManager manager];
              mgr2.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                                @"text/html",
                                                                @"image/jpeg",
                                                                @"image/png",
                                                                @"application/octet-stream",
                                                                @"text/json",
                                                                nil];
              
              [mgr2 POST:[NSString stringWithFormat:@"%@?c=Package&&a=evaluate",requestURL]
              parameters:@{@"packageID" : self.comboID,
                           @"page" : @"1",
                           @"pageSize" : @"10"}
                progress:nil
                 success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                     if ([responseObject[@"state"] isEqualToString:@"SUCCESS"]) {
                         NSLog(@"评论 %@", responseObject[@"data"]);
                         self.comments = responseObject[@"data"];
                         //设置评论模块
                         [self setupCommentView];
                     }
                     else {
                         
                     }
                 }
                 failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                 }];

          }
          else {
              [SVProgressHUD showWithStatus:responseObject[@"state"]];
              dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                  [SVProgressHUD dismiss];
              });
          }
      }
      failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          [SVProgressHUD showWithStatus:@"错误"];
          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
              [SVProgressHUD dismiss];
          });
      }];
    
    
}

- (NSMutableArray *)photographerCellHeight {
    if (_photographerCellHeight == nil) {
        _photographerCellHeight = [NSMutableArray array];
    }
    return _photographerCellHeight;
}

- (NSMutableArray *)chooseBtns {
    if (_chooseBtns == nil) {
        _chooseBtns = [NSMutableArray array];
    }
    return _chooseBtns;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self preferredStatusBarStyle];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0xec / 255.0 green:0xf5 / 255.0 blue:0xfc / 255.0 alpha:1.0];
    //右边BarButtonItem
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:@"share_w" highLightImage:@"share_w" target:self action:@selector(share)];
    [self getData];
}

- (void)setupContentScrollView {
    UIScrollView *scrollV = [[UIScrollView alloc]init];
    scrollV.delegate = self;
    self.scrollV = scrollV;
    scrollV.frame = CGRectMake(0, -20, screenW, screenH - screenW / 375.0 * 60 + 20);
    scrollV.contentSize = CGSizeMake(0, screenW / 375.0 * (250 +100) + 10 + 30 + self.photographerCount * 80 + 10 + 35 + 2 * 60 + 10);
    scrollV.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:scrollV];
}
//根据拖动多少实现navBar的隐藏
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.navigationController.navigationBar.hidden = scrollView.contentOffset.y == 0;
    self.navigationController.navigationBar.alpha = scrollView.contentOffset.y / 64.0 + 0.01;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.alpha = 1.0;
}

- (void)setupTopImagePlayer {
    ImageViewPlayer *imageViewPlayer = [ImageViewPlayer imageViewPlayer];
    imageViewPlayer.frame = CGRectMake(0, 0, screenW, screenW / 375.0 * 250);
    
    //获取图片轮播的图片数量
    NSArray *imgs = self.data[@"imgs"];
    NSUInteger picCount = imgs.count;
    self.picCount = picCount;
    NSMutableArray *picViews = [NSMutableArray array];
    for (NSInteger i = 0; i < picCount; i++) {
        UIImageView *imgV = [[UIImageView alloc]init];
        imgV.tag = i;
        [imgV sd_setImageWithURL:[NSURL URLWithString:imgs[i]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
        [picViews addObject:imgV];
        //添加点击事件
        imgV.userInteractionEnabled = YES;
        [imgV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnTopImgV:)]];
    }

    
    imageViewPlayer.views = picViews;
    self.picViews = picViews;
    [imageViewPlayer hideNumberCount];
    
    [self.scrollV addSubview:imageViewPlayer];
}

//点击图片轮播器的图片弹出图片预览
#pragma mark - collection view delegate
//点击事件
- (void)tapOnTopImgV:(UITapGestureRecognizer *)tap {
    UIImageView *imgV = (UIImageView *)tap.view;
    
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithCurrentImageIndex:imgV.tag imageCount:self.picCount datasource:self];
    [browser hideChooseBtn];
    browser.browserStyle = XLPhotoBrowserStyleSimple;
}
#pragma mark    -   XLPhotoBrowserDatasource

- (UIImage *)photoBrowser:(XLPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
    UIImageView *img = self.picViews[index];
    return img.image;
}

- (UIView *)photoBrowser:(XLPhotoBrowser *)browser sourceImageViewForIndex:(NSInteger)index
{
    return self.picViews[index];
}

- (void)setupTopBackShareBtns {
    UIImageView *backImg = [[UIImageView alloc]init];
    backImg.frame = CGRectMake(14, 50, 40, 24);
    backImg.image = [UIImage imageNamed:@"back_black"];
    backImg.contentMode = UIViewContentModeLeft;
    backImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *backGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pop)];
    [backImg addGestureRecognizer:backGes];
    [self.scrollV addSubview:backImg];
    
    UIImageView *shareImg = [[UIImageView alloc]init];
    shareImg.frame = CGRectMake(screenW - 40 - 14, 50, 40, 24);
    shareImg.image = [UIImage imageNamed:@"share"];
    shareImg.contentMode = UIViewContentModeRight;
    shareImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *shareGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share)];
    [shareImg addGestureRecognizer:shareGes];
    [self.scrollV addSubview:shareImg];
}

- (void)setupPriceView {
    UIView *priceView = [[UIView alloc]init];
    priceView.backgroundColor = [UIColor whiteColor];
    priceView.frame = CGRectMake(0, screenW / 375.0 * 250, screenW, screenW / 375.0 * 100);
    
    [self.scrollV addSubview:priceView];
    //价格的Label
    UILabel *priceLabel = [[UILabel alloc]init];
    priceLabel.text = [NSString stringWithFormat:@"¥ %@", self.data[@"price"]];
    priceLabel.font = [UIFont boldSystemFontOfSize:screenW / 375.0 * 26];
    priceLabel.textColor = [UIColor colorWithRed:0xfc /255.0 green:0x4a /255.0 blue:0x83 /255.0 alpha:1.0];
    [priceLabel sizeToFit];
    priceLabel.origin = CGPointMake(screenW * 0.5 - priceLabel.frame.size.width * 0.5, 7);
    [priceView addSubview:priceLabel];
    
    //服装 拍摄时间 底片 以及查看详情按钮
    NSArray *servers = self.data[@"servers"];
    
    UIImageView *clothesImg = [[UIImageView alloc]init];
    clothesImg.frame = CGRectMake(screenW / 375.0 * 48, priceLabel.bottom + 8, 15, 14);
    [clothesImg sd_setImageWithURL:[NSURL URLWithString:servers[0][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
    UILabel *clothesLbl = [[UILabel alloc]init];
    clothesLbl.text = servers[0][@"title"];
    clothesLbl.font = [UIFont systemFontOfSize:12.0];
    clothesLbl.textColor = [UIColor colorWithRed:0x8d /255.0 green:0xa5 /255.0 blue:0xb8 /255.0 alpha:1.0];
    [clothesLbl sizeToFit];
    clothesLbl.origin = CGPointMake(clothesImg.center.x - clothesLbl.frame.size.width * 0.5, clothesImg.bottom + 8);
    
    UIImageView *timeImg = [[UIImageView alloc]init];
    timeImg.frame = CGRectMake(screenW / 375.0 * 129, priceLabel.bottom + 8, 14, 14);
    [timeImg sd_setImageWithURL:[NSURL URLWithString:servers[1][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
    UILabel *timeLbl = [[UILabel alloc]init];
    timeLbl.text = servers[1][@"title"];
    timeLbl.font = [UIFont systemFontOfSize:12.0];
    timeLbl.textColor = [UIColor colorWithRed:0x8d /255.0 green:0xa5 /255.0 blue:0xb8 /255.0 alpha:1.0];
    [timeLbl sizeToFit];
    timeLbl.origin = CGPointMake(timeImg.center.x - timeLbl.frame.size.width * 0.5, timeImg.bottom + 8);
    
    UIImageView *picImg = [[UIImageView alloc]init];
    picImg.frame = CGRectMake(screenW / 375.0 * 209, priceLabel.bottom + 8, 19, 14);
    [picImg sd_setImageWithURL:[NSURL URLWithString:servers[2][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
    UILabel *picLbl = [[UILabel alloc]init];
    picLbl.text = servers[2][@"title"];
    picLbl.font = [UIFont systemFontOfSize:12.0];
    picLbl.textColor = [UIColor colorWithRed:0x8d /255.0 green:0xa5 /255.0 blue:0xb8 /255.0 alpha:1.0];
    [picLbl sizeToFit];
    picLbl.origin = CGPointMake(picImg.center.x - picLbl.frame.size.width * 0.5, picImg.bottom + 8);
    
    UIButton *detailBtn = [[UIButton alloc]init];
    [detailBtn setTitle:@"查看详情" forState:UIControlStateNormal];
    [detailBtn.titleLabel setFont:[UIFont systemFontOfSize:screenW / 375.0 * 14.0]];
    [detailBtn setTitleColor:[UIColor colorWithRed:0x76 /255.0 green:0xb1 /255.0 blue:0xfd /255.0 alpha:1.0] forState:UIControlStateNormal];
    [detailBtn setBackgroundImage:[UIImage imageNamed:@"detailBtnBg"] forState:UIControlStateNormal];
    detailBtn.frame = CGRectMake(screenW / 375.0 * 280, priceLabel.bottom + 15, screenW / 375.0 * 84, 24);
    
    [detailBtn addTarget:self action:@selector(comboDetail) forControlEvents:UIControlEventTouchUpInside];
    
    [priceView addSubview:detailBtn];
    [priceView addSubview:clothesImg];
    [priceView addSubview:clothesLbl];
    [priceView addSubview:timeImg];
    [priceView addSubview:timeLbl];
    [priceView addSubview:picImg];
    [priceView addSubview:picLbl];
}
//弹出套餐详情页面
- (void)comboDetail {
    BPComboDetailView *detailView = [[[NSBundle mainBundle]loadNibNamed:@"BPComboDetailView" owner:nil options:nil]lastObject];
    //
    NSArray *servers = self.data[@"servers"];
    NSLog(@"套餐详情 %@", servers);
    [detailView setData:servers];
    detailView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:detailView];
}


- (void)pop {
    [self.navigationController popViewControllerAnimated:YES];
}
//分享按钮
- (void)share {
    //弹出半透明黑色背景
    UIView *bgView = [[UIView alloc]init];
    bgView.frame = [UIScreen mainScreen].bounds;
    bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    
    UIView *shareView = [[UIView alloc]init];
    shareView.frame =CGRectMake(0, screenH - screenW / 375.0 * 210, screenW, screenW / 375.0 * 210);
    shareView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.85];
    [bgView addSubview:shareView];
    
    UILabel *shareToLbl = [[UILabel alloc]init];
    shareToLbl.text = @"分享至";
    shareToLbl.textColor = [UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0];
    shareToLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 16.0];
    [shareToLbl sizeToFit];
    shareToLbl.center = CGPointMake(screenW * 0.5, 14 + shareToLbl.frame.size.height * 0.5);
    [shareView addSubview:shareToLbl];
    
    //三个分享的按钮
    UIButton *wechat = [UIButton buttonWithType:UIButtonTypeCustom];
    wechat.frame = CGRectMake(42, shareToLbl.bottom + 21, screenW / 375.0 * 56, screenW / 375.0 * 58);
    [wechat setBackgroundImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
    [shareView addSubview:wechat];
    
    UILabel *wechatLbl = [[UILabel alloc]init];
    wechatLbl.text = @"微信好友";
    wechatLbl.textColor = [UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0];
    wechatLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 12.0];
    [wechatLbl sizeToFit];
    wechatLbl.center = CGPointMake(wechat.center.x, wechat.bottom + 12 +wechatLbl.frame.size.height * 0.5);
    [shareView addSubview:wechatLbl];
    
    UIButton *friend = [UIButton buttonWithType:UIButtonTypeCustom];
    friend.frame = CGRectMake(screenW * 0.5 - 56 * 0.5, shareToLbl.bottom + 21,screenW / 375.0 * 56,screenW / 375.0 * 58);
    [friend setBackgroundImage:[UIImage imageNamed:@"friend"] forState:UIControlStateNormal];
    [shareView addSubview:friend];
    
    UILabel *friendLbl = [[UILabel alloc]init];
    friendLbl.text = @"朋友圈";
    friendLbl.textColor = [UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0];
    friendLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 12.0];
    [friendLbl sizeToFit];
    friendLbl.center = CGPointMake(friend.center.x, wechat.bottom + 12 +friendLbl.frame.size.height * 0.5);
    [shareView addSubview:friendLbl];
    
    UIButton *qq = [UIButton buttonWithType:UIButtonTypeCustom];
    qq.frame = CGRectMake(screenW - 42 - 56, shareToLbl.bottom + 21,screenW / 375.0 * 56,screenW / 375.0 * 58);
    [qq setBackgroundImage:[UIImage imageNamed:@"qq"] forState:UIControlStateNormal];
    [shareView addSubview:qq];
    
    UILabel *qqLbl = [[UILabel alloc]init];
    qqLbl.text = @"QQ";
    qqLbl.textColor = [UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0];
    qqLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 12.0];
    [qqLbl sizeToFit];
    qqLbl.center = CGPointMake(qq.center.x, wechat.bottom + 12 +qqLbl.frame.size.height * 0.5);
    [shareView addSubview:qqLbl];
    
    //取消分享
    UIButton *cancel = [UIButton buttonWithType:0];
    cancel.backgroundColor = [UIColor whiteColor];
    cancel.frame = CGRectMake(0, shareView.frame.size.height - 52, screenW, 52);
    [cancel setTitle:@"取消" forState:UIControlStateNormal];
    [cancel.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
    [cancel setTitleColor:[UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0] forState:UIControlStateNormal];
    [shareView addSubview:cancel];
    
    [cancel addTarget:self action:@selector(cancelShare:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:bgView];
}

- (void)cancelShare:(UIButton *)cancel {
    //获取到bgView
    UIView *bgView = [[cancel superview] superview];
    [bgView removeFromSuperview];
}

- (void)setupPhotographerView {
    UIView *photographerView = [[UIView alloc]init];
    photographerView.backgroundColor = [UIColor whiteColor];
    //一个摄影师cell高度为80
    photographerView.frame = CGRectMake(10, screenW / 375.0 * (250 + 100) + 10, screenW - 20, 30 + self.photographerCount * 80);
    photographerView.layer.cornerRadius = 8.0;
    photographerView.layer.masksToBounds = YES;
    
    //添加阴影
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(photographerView.layer.frame.origin.x, photographerView.layer.frame.origin.y, photographerView.layer.frame.size.width, photographerView.layer.frame.size.height);
    layer.backgroundColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8].CGColor;
    layer.shadowColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8].CGColor;
    layer.shadowOffset = CGSizeMake(0, 2);
    layer.shadowOpacity = 1.0;
    layer.shadowRadius = 3;
    layer.cornerRadius = 8;
    [self.scrollV.layer insertSublayer:layer below:photographerView.layer];
    
    //添加顶栏
    UIView *blueV = [[UIView alloc]init];
    blueV.frame = CGRectMake(0, 8, 6, 22);
    blueV.backgroundColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8];
    [photographerView addSubview:blueV];
    
    UILabel *photographerLbl = [[UILabel alloc]init];
    photographerLbl.text = @"摄影师";
    photographerLbl.textColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8];
    photographerLbl.font = [UIFont boldSystemFontOfSize:screenW / 375.0 * 16.0];
    [photographerLbl sizeToFit];
    photographerLbl.origin = CGPointMake(10, 10);
    [photographerView addSubview:photographerLbl];
    
    UILabel *viewMoreLbl = [[UILabel alloc]init];
    viewMoreLbl.text = @"点击头像查看更多";
    viewMoreLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 12.0];
    viewMoreLbl.textColor = [UIColor colorWithRed:0xb9 / 255.0 green:0xc6 / 255.0 blue:0xd0 / 255.0 alpha:0.8];
    [viewMoreLbl sizeToFit];
    viewMoreLbl.origin = CGPointMake(65, 13);
    [photographerView addSubview:viewMoreLbl];
    //摄影师的tableView
    UITableView *photographerTableView = [[UITableView alloc]init];
    self.photographerTableView = photographerTableView;
    
    float photographerTableViewHeight = 0;
    for (NSInteger i = 0; i < self.photographerCount; i++) {
        photographerTableViewHeight += [self.photographerCellHeight[i] floatValue];
    }
    photographerTableView.frame = CGRectMake(0, 30, screenW - 20, photographerTableViewHeight);
    
    photographerTableView.dataSource = self;
    photographerTableView.delegate = self;
    [photographerTableView registerNib:[UINib nibWithNibName:@"BPPhotographerTableViewCell" bundle:nil] forCellReuseIdentifier:@"photographerCell"];
    
    
    [photographerView addSubview:photographerTableView];
    
    [self.scrollV addSubview:photographerView];
}
#pragma mark - 摄影师table view数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.photographerCount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BPPhotographerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"photographerCell"];
    cell.headerImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"combo_%li", (long)indexPath.row]];
    
    [cell.chooseBtn addTarget:self action:@selector(choosePhotographerTime:) forControlEvents:UIControlEventTouchUpInside];
    cell.chooseBtn.tag = indexPath.row;
    [self.chooseBtns addObject:cell.chooseBtn];
    
    NSArray *photographersData = self.data[@"photographers"];
    
    [cell.headerImg sd_setImageWithURL:[NSURL URLWithString:photographersData[indexPath.row][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    cell.name.text = photographersData[indexPath.row][@"name"];
    //描述的label
    UILabel *desc = [[UILabel alloc] init];
    desc.text = photographersData[indexPath.row][@"desc"];
    desc.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    desc.textColor = [UIColor colorWithRed:141/255.0 green:165/255.0 blue:184/255.0 alpha:1/1.0];
    desc.origin = CGPointZero;
    [desc sizeToFit];
    
    CGFloat rowHeight = desc.frame.size.height;
    UIScrollView *descScroll = [[UIScrollView alloc]init];
    descScroll.frame = CGRectMake(cell.name.frame.origin.x, cell.name.bottom + 3, screenW - cell.name.frame.origin.x - 25, rowHeight * 2);
    
    desc.frame = CGRectMake(0, 0, descScroll.frame.size.width, 0);
    
    desc.numberOfLines = 0; //PS：这句很主要，否则默认行数为1，只显示一行文字后面截断了就没有了
    CGRect myRect = [desc boundingRectWithInitSize:desc.frame.size];
    desc.frame = CGRectMake(0, 0, descScroll.frame.size.width, myRect.size.height);
    [descScroll addSubview:desc];
    descScroll.contentSize = CGSizeMake(0, desc.frame.size.height);
    
    [cell.contentView addSubview:descScroll];
    
    //获取星级
    NSInteger star = [photographersData[indexPath.row][@"star_level"] integerValue];
    switch (star) {
        case 0:
        {
            [cell.star1 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star2 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star3 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star4 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star5 setImage:[UIImage imageNamed:@"star_n"]];
        }
            break;
        case 1:
        {
            [cell.star2 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star3 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star4 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star5 setImage:[UIImage imageNamed:@"star_n"]];
        }
            break;
        case 2:
        {
            [cell.star3 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star4 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star5 setImage:[UIImage imageNamed:@"star_n"]];
        }
            break;
        case 3:
        {
            [cell.star4 setImage:[UIImage imageNamed:@"star_n"]];
            [cell.star5 setImage:[UIImage imageNamed:@"star_n"]];
        }
            break;
        case 4:
        {
            [cell.star5 setImage:[UIImage imageNamed:@"star_n"]];
        }
            break;
        case 5:
        {
            
        }
            break;
        default:
            break;
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.tag = indexPath.row;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedPhotographerCell = (BPPhotographerTableViewCell *)[self.photographerTableView cellForRowAtIndexPath:indexPath];
    BPPhotographerViewController *photographerVC = [[BPPhotographerViewController alloc]init];
    photographerVC.delegate = self;
    photographerVC.photographerID = self.data[@"photographers"][indexPath.row][@"id"];
    [self.navigationController pushViewController:photographerVC animated:YES];
}

//点击“选择他”按钮 弹出时间

- (void)choosePhotographerTime:(UIButton *)chooseBtn {
    //如果有选中的摄影师，则不可选别的
    for (UIButton *choose in self.chooseBtns) {

        if (choose.isSelected) {
            choose.selected = NO;
            choose.backgroundColor = [UIColor colorWithRed:216/255.0 green:216/255.0 blue:216/255.0 alpha:1/1.0];
            for (UIView *view in self.selectedPhotographerCell.subviews) {
                //显示星星
                if ([view isKindOfClass:[UIImageView class]]) {
                    if (view.tag != 0) {
                        view.hidden = NO;
                    }
                }
                //移除选定时间的label
                if ([view isKindOfClass:[UILabel class]]) {
                    if (view.tag == 99) {
                        [view removeFromSuperview];
                    }
                }
            }
            return;
        }
    }
    
    
    [SVProgressHUD showWithStatus:@"读取中"];
    //摄影师的id
    NSString *photographerID = self.data[@"photographers"][chooseBtn.tag][@"id"];
    self.photographer_id = photographerID;
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                     @"text/html",
                                                     @"image/jpeg",
                                                     @"image/png",
                                                     @"application/octet-stream",
                                                     @"text/json",
                                                     nil];
    
    [mgr POST:[NSString stringWithFormat:@"%@?c=Photographer&&a=workDay",requestURL]
   parameters:@{@"photographerID" : photographerID} progress:^(NSProgress * _Nonnull uploadProgress) {
       
   } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       if ([responseObject[@"state"] isEqualToString:@"SUCCESS"]) {
           NSArray *data = responseObject[@"data"];
           NSLog(@"摄影师时间%@", data);
           self.photographerTimes = data;
           [SVProgressHUD dismiss];
           BPPhotographerTableViewCell *selectedPhotographerCell = (BPPhotographerTableViewCell *)[chooseBtn superview];
           self.selectedPhotographerCell = selectedPhotographerCell;
           
           //弹出半透明黑色背景
           UIView *bgView = [[UIView alloc]init];
           bgView.frame = [UIScreen mainScreen].bounds;
           bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
           //下方的白色view
           UIView *chooseTimeView = [[UIView alloc]init];
           chooseTimeView.frame =CGRectMake(0, screenH - screenW / 375.0 * 260, screenW, screenW / 375.0 * 260);
           chooseTimeView.backgroundColor = [UIColor whiteColor];
           [bgView addSubview:chooseTimeView];
           //顶部的“选择服务时间”Label 和 X按钮
           UILabel *topLabel = [[UILabel alloc]init];
           topLabel.text = @"选择服务时间";
           topLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:16];
           topLabel.textColor = [UIColor colorWithRed:141/255.0 green:165/255.0 blue:184/255.0 alpha:1/1.0];
           [topLabel sizeToFit];
           topLabel.center = CGPointMake(screenW * 0.5, screenW / 375.0 * 14 + topLabel.frame.size.height * 0.5);
           [chooseTimeView addSubview:topLabel];
           
           UIButton *cancelBtn = [[UIButton alloc]init];
           [cancelBtn setBackgroundImage:[UIImage imageNamed:@"cancel"] forState:UIControlStateNormal];
           [cancelBtn sizeToFit];
           cancelBtn.center = CGPointMake(screenW - screenW / 375.0 * 21 - cancelBtn.frame.size.width * 0.5, topLabel.center.y);
           [cancelBtn addTarget:self action:@selector(cancelChooseTime:) forControlEvents:UIControlEventTouchUpInside];
           
           [chooseTimeView addSubview:cancelBtn];
           //日期拖动条和日历按钮
           UIView *dateView = [[UIView alloc]init];
           dateView.backgroundColor = [UIColor colorWithRed:236/255.0 green:245/255.0 blue:252/255.0 alpha:1/1.0];
           dateView.frame = CGRectMake(0, screenW / 375.0 * 50, screenW, screenW / 375.0 * 52);
           [chooseTimeView addSubview:dateView];
           
           UIScrollView *dateScrollView = [[UIScrollView alloc]init];
           dateScrollView.showsHorizontalScrollIndicator = NO;
           dateScrollView.backgroundColor = [UIColor clearColor];
           dateScrollView.frame = CGRectMake(0, 0, screenW , dateView.frame.size.height);
           dateScrollView.contentSize = CGSizeMake(data.count * screenW / 375.0 * 83, 0);
           
           //三个时间段的选择的view
           UIView *leftView = [[UIView alloc]init];
           leftView.frame = CGRectMake(screenW / 375.0 * 10, dateView.bottom + screenW / 375.0 * 8, (screenW - screenW / 375.0 * 10 * 4) * 0.33, screenW / 375.0 * 80);
           leftView.backgroundColor = [UIColor colorWithRed:0xB9/255.0 green:0xc6/255.0 blue:0xd0/255.0 alpha:1/1.0];
           
           UIView *midView = [[UIView alloc]init];
           midView.frame = CGRectMake(leftView.right + screenW / 375.0 * 10, dateView.bottom + screenW / 375.0 * 8, (screenW - screenW / 375.0 * 10 * 4) * 0.33, screenW / 375.0 * 80);
           midView.backgroundColor = [UIColor colorWithRed:0xB9/255.0 green:0xc6/255.0 blue:0xd0/255.0 alpha:1/1.0];
           
           UIView *rightView = [[UIView alloc]init];
           rightView.frame = CGRectMake(midView.right + screenW / 375.0 * 10, dateView.bottom + screenW / 375.0 * 8, (screenW - screenW / 375.0 * 10 * 4) * 0.33, screenW / 375.0 * 80);
           rightView.backgroundColor = [UIColor colorWithRed:0xB9/255.0 green:0xc6/255.0 blue:0xd0/255.0 alpha:1/1.0];
           
           //根据当天可预约与否，判定整天3个时间段的可预约状况
           
           BPTimeChooseView *innerLeftView = [[BPTimeChooseView alloc]init];
           innerLeftView.tag = 0;
           innerLeftView.delegate = self;
           innerLeftView.frame = CGRectMake(1, 1, leftView.frame.size.width - 2, leftView.frame.size.height - 2);
           self.innerLeftView = innerLeftView;
           
           UILabel *leftLabel = [[UILabel alloc]init];
           self.leftLabel = leftLabel;
           leftLabel.text = @"09:30\n -- \n11:30";
           leftLabel.numberOfLines = 5;
           leftLabel.textAlignment = NSTextAlignmentCenter;
           leftLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
           [leftLabel sizeToFit];
           leftLabel.center = CGPointMake(innerLeftView.frame.size.width * 0.5, innerLeftView.frame.size.height * 0.5);
           [innerLeftView addSubview:leftLabel];
//           innerLeftView.timeChooseType = TimeChooseTypeChooseable;
           
           BPTimeChooseView *innerMidView = [[BPTimeChooseView alloc]init];
           innerMidView.tag = 1;
           innerMidView.delegate = self;
           innerMidView.frame = CGRectMake(1, 1, leftView.frame.size.width - 2, leftView.frame.size.height - 2);
           self.innerMidView = innerMidView;
           
           UILabel *midLabel = [[UILabel alloc]init];
           self.midLabel = midLabel;
           midLabel.text = @"13:30\n -- \n15:30";
           midLabel.numberOfLines = 5;
           midLabel.textAlignment = NSTextAlignmentCenter;
           midLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
           [midLabel sizeToFit];
           midLabel.center = CGPointMake(innerLeftView.frame.size.width * 0.5, innerLeftView.frame.size.height * 0.5);
           [innerMidView addSubview:midLabel];
//           innerMidView.timeChooseType = TimeChooseTypeUnchooseable;
           
           BPTimeChooseView *innerRightView = [[BPTimeChooseView alloc]init];
           innerRightView.tag = 2;
           innerRightView.delegate = self;
           innerRightView.frame = CGRectMake(1, 1, leftView.frame.size.width - 2, leftView.frame.size.height - 2);
           self.innerRightView = innerRightView;
           
           UILabel *rightLabel = [[UILabel alloc]init];
           self.rightLabel = rightLabel;
           rightLabel.text = @"15:30\n -- \n17:30";
           rightLabel.numberOfLines = 5;
           rightLabel.textAlignment = NSTextAlignmentCenter;
           rightLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
           
           [rightLabel sizeToFit];
           rightLabel.center = CGPointMake(innerLeftView.frame.size.width * 0.5, innerLeftView.frame.size.height * 0.5);
           [innerRightView addSubview:rightLabel];
//           innerRightView.timeChooseType = TimeChooseTypeChooseable;
           
           
           [leftView addSubview:innerLeftView];
           [midView addSubview:innerMidView];
           [rightView addSubview:innerRightView];
           
           [chooseTimeView addSubview:leftView];
           [chooseTimeView addSubview:midView];
           [chooseTimeView addSubview:rightView];
           
           //创建多个view 加入到scrollView中去
           for (NSInteger i = 0; i < data.count; i++) {
               //设置明天的时间段可选择情况
               if (i == 1) {
                   if ([data[i][@"state"] integerValue] == 0) {
                       innerLeftView.timeChooseType = TimeChooseTypeUnchooseable;
                       innerMidView.timeChooseType = TimeChooseTypeUnchooseable;
                       innerRightView.timeChooseType = TimeChooseTypeUnchooseable;
                   }
                   else {
                       NSArray *times = data[i][@"times"];
                       NSDateFormatter *format=[[NSDateFormatter alloc]init];
                       [format setDateFormat:@"HH:mm"];
                       //第一个时间段
                       NSDate *startTime1 = [NSDate dateWithTimeIntervalSince1970:[times[0][@"s_time"] doubleValue]];
                       NSString *startTime1String = [format stringFromDate:startTime1];
                       
                       NSDate *endTime1 = [NSDate dateWithTimeIntervalSince1970:[times[0][@"e_time"] doubleValue]];
                       NSString *endTime1String = [format stringFromDate:endTime1];
                       
                       leftLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime1String, endTime1String];
                       //第二个时间段
                       NSDate *startTime2 = [NSDate dateWithTimeIntervalSince1970:[times[1][@"s_time"] doubleValue]];
                       NSString *startTime2String = [format stringFromDate:startTime2];
                       
                       NSDate *endTime2 = [NSDate dateWithTimeIntervalSince1970:[times[1][@"e_time"] doubleValue]];
                       NSString *endTime2String = [format stringFromDate:endTime2];
                       
                       midLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime2String, endTime2String];
                       //第三个时间段
                       NSDate *startTime3 = [NSDate dateWithTimeIntervalSince1970:[times[2][@"s_time"] doubleValue]];
                       NSString *startTime3String = [format stringFromDate:startTime3];
                       
                       NSDate *endTime3 = [NSDate dateWithTimeIntervalSince1970:[times[2][@"e_time"] doubleValue]];
                       NSString *endTime3String = [format stringFromDate:endTime3];
                       
                       rightLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime3String, endTime3String];
                       
                       innerLeftView.timeChooseType = [times[0][@"state"] integerValue] == 1? TimeChooseTypeChooseable : TimeChooseTypeUnchooseable;
                       innerMidView.timeChooseType = [times[1][@"state"] integerValue] == 1 ? TimeChooseTypeChooseable : TimeChooseTypeUnchooseable;
                       innerRightView.timeChooseType = [times[2][@"state"] integerValue] == 1 ? TimeChooseTypeChooseable : TimeChooseTypeUnchooseable;
                   }
               }
               
               NSDate *date = [NSDate dateWithTimeIntervalSince1970:[data[i][@"day"] unsignedIntegerValue]];
               NSDateFormatter *format1=[[NSDateFormatter alloc]init];
               [format1 setDateFormat:@"MM/dd"];
               NSString *str1=[format1 stringFromDate:date];
               
               UIView *dateCellView = [[UIView alloc]initWithFrame:CGRectMake(i * screenW / 375.0 * 83, 0, screenW / 375.0 * 83, dateView.frame.size.height)];
               dateCellView.tag = i;
               dateCellView.backgroundColor = [UIColor clearColor];
               //给cellView添加点击事件
               UITapGestureRecognizer *tapOnDateCellView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOnDateCellView:)];
               [dateCellView addGestureRecognizer:tapOnDateCellView];
               
               
               UILabel *dateLabel = [[UILabel alloc]init];
               
               NSString *prefixDate = [NSString string];
               prefixDate = i == 0 ? @"今天" : i == 1 ? @"明天" : @"后天";
               if (i > 2) {
                   prefixDate = [self weekdayStringFromDate:date];
               }
               
               dateLabel.text = [NSString stringWithFormat:@"%@ %@", prefixDate, str1];
               if (i == 1) {
                   self.selectedDate = dateLabel.text;
               }
               dateLabel.tag = 10;
               dateLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:screenW / 375.0 * 13.0];
               dateLabel.textColor = [UIColor colorWithRed:141/255.0 green:165/255.0 blue:184/255.0 alpha:1/1.0];
               [dateLabel sizeToFit];
               dateLabel.center = CGPointMake(dateCellView.frame.size.width * 0.5, screenW / 375.0 * 10 + dateLabel.frame.size.height * 0.5);
               [dateCellView addSubview:dateLabel];
               
               UILabel *status = [[UILabel alloc]init];
               status.text = data[i][@"stateDesc"];
               status.font = [UIFont fontWithName:@"PingFangSC-Regular" size:screenW / 375.0 * 11.0];
               status.textColor = [UIColor colorWithRed:185/255.0 green:198/255.0 blue:208/255.0 alpha:1/1.0];
               [status sizeToFit];
               status.center = CGPointMake(dateCellView.frame.size.width * 0.5, dateCellView.frame.size.height - screenW / 375.0 * 7 - status.frame.size.height * 0.5);
               [dateCellView addSubview:status];
               if (i == 1) {
                   self.selectedDateCell = dateCellView;
                   [self tapOnDateCellView:tapOnDateCellView];
               }
               
               [dateScrollView addSubview:dateCellView];
           }
           
           [dateView addSubview:dateScrollView];
           
           //分割线
           UIView *separatorLine = [[UIView alloc]init];
           separatorLine.frame = CGRectMake(0, leftView.bottom + screenW / 375.0 * 10, screenW, 0.5);
           separatorLine.backgroundColor = [UIColor colorWithRed:0xd8/255.0 green:0xd8/255.0 blue:0xd8/255.0 alpha:1/1.0];
           [chooseTimeView addSubview:separatorLine];
           
           //底部两个按钮
           UIButton *cancel = [[UIButton alloc]init];
           cancel.backgroundColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
           cancel.frame = CGRectMake(screenW / 375.0 * 10, separatorLine.bottom + screenW / 375.0 * 10, (screenW - (screenW / 375.0 * 10 * 3)) * 0.5, screenW / 375.0 * 40);
           [cancel setTitle:@"返回" forState:UIControlStateNormal];
           [cancel.titleLabel setFont:[UIFont fontWithName:@"PingFangSC-Medium" size:16]];
           [cancel setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1/1.0] forState:UIControlStateNormal];
           cancel.layer.cornerRadius = 4.0;
           [chooseTimeView addSubview:cancel];
           
           [cancel addTarget:self action:@selector(cancelChooseTime:) forControlEvents:UIControlEventTouchUpInside];
           
           UIButton *confirm = [[UIButton alloc]init];
           confirm.backgroundColor = [UIColor colorWithRed:118/255.0 green:177/255.0 blue:253/255.0 alpha:1/1.0];
           confirm.frame = CGRectMake(cancel.right + screenW / 375.0 * 10, separatorLine.bottom + screenW / 375.0 * 10, (screenW - (screenW / 375.0 * 10 * 3)) * 0.5, screenW / 375.0 * 40);
           [confirm setTitle:@"确定" forState:UIControlStateNormal];
           [confirm.titleLabel setFont:[UIFont fontWithName:@"PingFangSC-Medium" size:16]];
           [confirm setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1/1.0] forState:UIControlStateNormal];
           confirm.layer.cornerRadius = 4.0;
           //确定摄影师按钮
           [confirm addTarget:self action:@selector(confirmPhotographer:) forControlEvents:UIControlEventTouchUpInside];
           [chooseTimeView addSubview:confirm];
           
           [self.view addSubview:bgView];
       }
       else {
           [SVProgressHUD showWithStatus:@"请求失败"];
           dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
               [SVProgressHUD dismiss];
           });
       }
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [SVProgressHUD showWithStatus:@"请求失败"];
       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
           [SVProgressHUD dismiss];
       });
   }];
}

- (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周天", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}

- (void)registerTime:(NSString *)selectedTime time_id:(NSInteger)time_id{
    //1. 去掉首尾空格和换行符
    selectedTime = [selectedTime stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    //2. 去掉所有空格和换行符
    selectedTime = [selectedTime stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    selectedTime = [selectedTime stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    self.selectedTime = selectedTime;
    self.selectedTimeIndex = time_id;
}

- (void)confirmPhotographer:(UIButton *)confirmBtn {
    //拦截未选择时间的情况
    if ([self.selectedTime length] == 0) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择一个服务时间段" message:nil preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction:ok];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
    }
    else {
        //获取cell内的"选择他"按钮
        for (UIView *view in self.selectedPhotographerCell.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
                UIButton *chooseBtn = (UIButton *)view;
                chooseBtn.backgroundColor = [UIColor colorWithRed:118/255.0 green:177/255.0 blue:253/255.0 alpha:1/1.0];
                chooseBtn.selected = YES;
                
                //获取预定的时间
                UILabel *label = [[UILabel alloc] init];
                label.text = [NSString stringWithFormat:@"%@ %@", self.selectedDate, self.selectedTime];
                label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
                label.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
                label.tag = 99;
                label.backgroundColor = [UIColor whiteColor];
                [label sizeToFit];
                
                label.frame = CGRectMake(68, 80 - label.frame.size.height - 5, screenW - 68 - 20, label.frame.size.height);
                label.backgroundColor = [UIColor whiteColor];
                
                [self.selectedPhotographerCell addSubview:label];
            }
            //隐藏星星
//            if ([view isKindOfClass:[UIImageView class]]) {
//                if (view.tag != 0) {
//                    view.hidden = YES;
//                }
//            }
        }
        UIView *bgView = [[confirmBtn superview]superview];
        [bgView removeFromSuperview];
    }
    self.time_id = self.photographerTimes[self.selectedDateIndex][@"times"][self.selectedTimeIndex][@"id"];
}

- (void)tapOnDateCellView:(UITapGestureRecognizer *)tap {
    for (UIView *view in tap.view.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)view;
            if (label.tag == 10) {
                self.selectedDate = label.text;
            }
        }
    }
    
    for (UIView *view in self.selectedDateCell.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)view;
            label.textColor = [UIColor colorWithRed:141/255.0 green:165/255.0 blue:184/255.0 alpha:1/1.0];
            
        }
        else {
            [view removeFromSuperview];
        }
    }
    
    NSLog(@"%@", self.selectedDate);
    UIView *dateCellView = tap.view;
    
    //根据tag获取点击dateCellView的index
    self.selectedDateIndex = dateCellView.tag;
    if ([self.photographerTimes[dateCellView.tag][@"state"] integerValue] == 0) {
        self.innerLeftView.timeChooseType = TimeChooseTypeUnchooseable;
        self.innerMidView.timeChooseType = TimeChooseTypeUnchooseable;
        self.innerRightView.timeChooseType = TimeChooseTypeUnchooseable;
    }
    else {
        NSArray *times = self.photographerTimes[dateCellView.tag][@"times"];
        NSDateFormatter *format=[[NSDateFormatter alloc]init];
        [format setDateFormat:@"HH:mm"];
        //第一个时间段
        NSDate *startTime1 = [NSDate dateWithTimeIntervalSince1970:[times[0][@"s_time"] doubleValue]];
        NSString *startTime1String = [format stringFromDate:startTime1];
        
        NSDate *endTime1 = [NSDate dateWithTimeIntervalSince1970:[times[0][@"e_time"] doubleValue]];
        NSString *endTime1String = [format stringFromDate:endTime1];
        
        self.leftLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime1String, endTime1String];
        //第二个时间段
        NSDate *startTime2 = [NSDate dateWithTimeIntervalSince1970:[times[1][@"s_time"] doubleValue]];
        NSString *startTime2String = [format stringFromDate:startTime2];
        
        NSDate *endTime2 = [NSDate dateWithTimeIntervalSince1970:[times[1][@"e_time"] doubleValue]];
        NSString *endTime2String = [format stringFromDate:endTime2];
        
        self.midLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime2String, endTime2String];
        //第三个时间段
        NSDate *startTime3 = [NSDate dateWithTimeIntervalSince1970:[times[2][@"s_time"] doubleValue]];
        NSString *startTime3String = [format stringFromDate:startTime3];
        
        NSDate *endTime3 = [NSDate dateWithTimeIntervalSince1970:[times[2][@"e_time"] doubleValue]];
        NSString *endTime3String = [format stringFromDate:endTime3];
        
        self.rightLabel.text = [NSString stringWithFormat:@"%@\n -- \n%@", startTime3String, endTime3String];
        
        self.innerLeftView.timeChooseType = [times[0][@"state"] integerValue] == 0 ? TimeChooseTypeUnchooseable : TimeChooseTypeChooseable;
        self.innerMidView.timeChooseType = [times[1][@"state"] integerValue] == 0 ? TimeChooseTypeUnchooseable : TimeChooseTypeChooseable;
        self.innerRightView.timeChooseType = [times[2][@"state"] integerValue] == 0 ? TimeChooseTypeUnchooseable : TimeChooseTypeChooseable;
    }
    
    for (UILabel *label in dateCellView.subviews) {
        label.textColor = [UIColor colorWithRed:118/255.0 green:177/255.0 blue:253/255.0 alpha:1/1.0];
    }
    
    UIView *bottomView = [[UIView alloc]init];
    bottomView.frame = CGRectMake(0, dateCellView.frame.size.height - 3, dateCellView.frame.size.width, 3);
    bottomView.backgroundColor = [UIColor colorWithRed:118/255.0 green:177/255.0 blue:253/255.0 alpha:1/1.0];
    [dateCellView addSubview:bottomView];
    self.selectedDateCell = dateCellView;
    
}

#pragma mark - collection view data source

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"dateCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 30;
}

- (void)cancelChooseTime:(UIButton *)button {
    UIView *bgView = [[button superview]superview];
    [bgView removeFromSuperview];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    float height = [self.photographerCellHeight[indexPath.row] floatValue];
    return height;
}

- (void)setupCommentView {
    
    UIView *commentView = [[UIView alloc]init];
    commentView.backgroundColor = [UIColor whiteColor];
    
    //添加顶栏
    UIView *blueV = [[UIView alloc]init];
    blueV.frame = CGRectMake(0, 8, 6, 22);
    blueV.backgroundColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8];
    [commentView addSubview:blueV];
    
    UILabel *commentLbl = [[UILabel alloc]init];
    commentLbl.text = @"评价";
    commentLbl.textColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8];
    commentLbl.font = [UIFont boldSystemFontOfSize:screenW / 375.0 * 16.0];
    [commentLbl sizeToFit];
    commentLbl.origin = CGPointMake(10, 10);
    [commentView addSubview:commentLbl];
    
    UILabel *viewMoreLbl = [[UILabel alloc]init];
    viewMoreLbl.text = @"查看更多 >";
    viewMoreLbl.font = [UIFont systemFontOfSize:screenW / 375.0 * 12.0];
    viewMoreLbl.textColor = [UIColor colorWithRed:0xb9 / 255.0 green:0xc6 / 255.0 blue:0xd0 / 255.0 alpha:0.8];
    [viewMoreLbl sizeToFit];
    viewMoreLbl.origin = CGPointMake(commentView.frame.size.width - 10 - viewMoreLbl.frame.size.width, 13);
    [commentView addSubview:viewMoreLbl];
    
    //根据套餐是否有评价来动态加载评价栏
    NSInteger commentCount = self.comments.count >= 2 ? 2 : self.comments.count;
    
    
    
    switch (commentCount) {
            //没有评论
        case 0:
        {
            UIView *noCommentView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, screenW - 20, 60)];
            noCommentView.backgroundColor = [UIColor whiteColor];
            
            UILabel *noCommentLbl = [[UILabel alloc]init];
            noCommentLbl.text = @"暂无评论";
            noCommentLbl.font = [UIFont fontWithName:@"PingFangSC-Regular" size:screenW / 375.0 * 16.0];
            noCommentLbl.textColor = [UIColor colorWithRed:139/255.0 green:163/255.0 blue:182/255.0 alpha:1/1.0];
            [noCommentLbl sizeToFit];
            noCommentLbl.center = CGPointMake(noCommentView.frame.size.width * 0.5, noCommentView.frame.size.height * 0.5);
            [noCommentView addSubview:noCommentLbl];
            
            [commentView addSubview:noCommentView];
            
            //更改外层scrollView的contentSize
            self.scrollV.contentSize = CGSizeMake(0, screenW / 375.0 * (250 +100) + 10 + 30 + self.photographerCount * 80 + 10 + 35 + 60 + 10);
            [self.view layoutIfNeeded];
        }
            break;
            //一条评论
        case 1:
        {
            //第一条评论
            UIImageView *commentHeader1 = [[UIImageView alloc]init];
            commentHeader1.frame = CGRectMake(10, 40, 30, 30);
            commentHeader1.layer.cornerRadius = 15.0;
            commentHeader1.layer.masksToBounds = YES;
            [commentHeader1 sd_setImageWithURL:[NSURL URLWithString:self.comments[0][@"user"][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
//            commentHeader1.image = [UIImage imageNamed:@"combo_0"];
            [commentView addSubview:commentHeader1];
            UILabel *commentName1 = [[UILabel alloc]init];
            commentName1.text = self.comments[0][@"user"][@"nickname"];
//            commentName1.text = @"用户1";
            commentName1.textColor = [UIColor colorWithRed:0x8d / 255.0 green:0xa5 / 255.0 blue:0xb8 / 255.0 alpha:1.0];
            commentName1.font = [UIFont systemFontOfSize:14.0];
            [commentName1 sizeToFit];
            commentName1.origin = CGPointMake(45, 45);
            [commentView addSubview:commentName1];
            UILabel *commentContent1 = [[UILabel alloc]init];
            commentContent1.text = self.comments[0][@"content"];
//            commentContent1.text = @"用户1的介绍";
            commentContent1.textColor = [UIColor colorWithRed:0xb9 / 255.0 green:0xc6 / 255.0 blue:0xd0 / 255.0 alpha:1.0];
            commentContent1.font = [UIFont systemFontOfSize:14.0];
            [commentContent1 sizeToFit];
            commentContent1.origin = CGPointMake(45, 70);
            [commentView addSubview:commentContent1];
            
            [commentView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushCommentVC)]];
            
            //更改外层scrollView的contentSize
            self.scrollV.contentSize = CGSizeMake(0, screenW / 375.0 * (250 +100) + 10 + 30 + self.photographerCount * 80 + 10 + 35 + 60 + 10);
            [self.view layoutIfNeeded];
        }
            break;
            //两条评论
        case 2:
        {
            //第一条评论
            UIImageView *commentHeader1 = [[UIImageView alloc]init];
            commentHeader1.frame = CGRectMake(10, 40, 30, 30);
            commentHeader1.layer.cornerRadius = 15.0;
            commentHeader1.layer.masksToBounds = YES;
                [commentHeader1 sd_setImageWithURL:[NSURL URLWithString:self.comments[0][@"user"][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
//            commentHeader1.image = [UIImage imageNamed:@"combo_0"];
            [commentView addSubview:commentHeader1];
            UILabel *commentName1 = [[UILabel alloc]init];
            commentName1.text = self.comments[0][@"user"][@"nickname"];
//            commentName1.text = @"用户1";
            commentName1.textColor = [UIColor colorWithRed:0x8d / 255.0 green:0xa5 / 255.0 blue:0xb8 / 255.0 alpha:1.0];
            commentName1.font = [UIFont systemFontOfSize:14.0];
            [commentName1 sizeToFit];
            commentName1.origin = CGPointMake(45, 45);
            [commentView addSubview:commentName1];
            UILabel *commentContent1 = [[UILabel alloc]init];
            commentContent1.text = self.comments[0][@"content"];
//            commentContent1.text = @"用户1的介绍";
            commentContent1.textColor = [UIColor colorWithRed:0xb9 / 255.0 green:0xc6 / 255.0 blue:0xd0 / 255.0 alpha:1.0];
            commentContent1.font = [UIFont systemFontOfSize:14.0];
            [commentContent1 sizeToFit];
            commentContent1.origin = CGPointMake(45, 70);
            [commentView addSubview:commentContent1];
            
            //分割线
            UIView *separator = [[UIView alloc]init];
            separator.backgroundColor = [UIColor colorWithRed:0xd8 / 255.0 green:0xd8 / 255.0 blue:0xd8 / 255.0 alpha:1.0];
            separator.frame = CGRectMake(10, 95, commentView.frame.size.width - 10, 0.5);
            [commentView addSubview:separator];
            //第2条评论
            UIImageView *commentHeader2 = [[UIImageView alloc]init];
            commentHeader2.frame = CGRectMake(10, 100, 30, 30);
            [commentHeader2 sd_setImageWithURL:[NSURL URLWithString:self.comments[0][@"user"][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
//            commentHeader2.image = [UIImage imageNamed:@"combo_1"];
            commentHeader2.layer.cornerRadius = 15.0;
            commentHeader2.layer.masksToBounds = YES;
            [commentView addSubview:commentHeader2];
            UILabel *commentName2 = [[UILabel alloc]init];
            commentName2.text = self.comments[0][@"user"][@"nickname"];
//            commentName2.text = @"用户2";
            commentName2.textColor = [UIColor colorWithRed:0x8d / 255.0 green:0xa5 / 255.0 blue:0xb8 / 255.0 alpha:1.0];
            commentName2.font = [UIFont systemFontOfSize:14.0];
            [commentName2 sizeToFit];
            commentName2.origin = CGPointMake(45, 105);
            [commentView addSubview:commentName2];
            UILabel *commentContent2 = [[UILabel alloc]init];
            commentContent2.text = self.comments[0][@"content"];
//            commentContent2.text = @"用户2的介绍";
            commentContent2.textColor = [UIColor colorWithRed:0xb9 / 255.0 green:0xc6 / 255.0 blue:0xd0 / 255.0 alpha:1.0];
            commentContent2.font = [UIFont systemFontOfSize:14.0];
            [commentContent2 sizeToFit];
            commentContent2.origin = CGPointMake(45, 130);
            [commentView addSubview:commentContent2];
            [commentView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushCommentVC)]];
        }
            break;
            
        default:
            break;
    }
    
    //一个评论cell高度为60
    if (commentCount == 2) {
        commentView.frame = CGRectMake(10, screenW / 375.0 * (250 + 100) + 10 + 30 + self.photographerCount * 80 + 10, screenW - 20, 35 + 2 * 60);
    }
    else {
        commentView.frame = CGRectMake(10, screenW / 375.0 * (250 + 100) + 10 + 30 + self.photographerCount * 80 + 10, screenW - 20, 35 + 60);
    }
    commentView.layer.cornerRadius = 8.0;
    commentView.layer.masksToBounds = YES;
    
    //添加阴影
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(commentView.layer.frame.origin.x, commentView.layer.frame.origin.y, commentView.layer.frame.size.width, commentView.layer.frame.size.height);
    layer.backgroundColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8].CGColor;
    layer.shadowColor = [UIColor colorWithRed:0x76 / 255.0 green:0xb1 / 255.0 blue:0xfd / 255.0 alpha:0.8].CGColor;
    layer.shadowOffset = CGSizeMake(0, 2);
    layer.shadowOpacity = 1.0;
    layer.shadowRadius = 3;
    layer.cornerRadius = 8;
    [self.scrollV.layer insertSublayer:layer below:commentView.layer];
    
    [self.scrollV addSubview:commentView];
}

- (void)pushCommentVC {
    BPCommentViewController *commentVC = [[BPCommentViewController alloc]init];
    commentVC.data = self.comments;
    commentVC.generalComment = self.generalComment;
    commentVC.title = @"评论";
    commentVC.view.backgroundColor = [UIColor colorWithRed:0xec / 255.0 green:0xf5 / 255.0 blue:0xfc / 255.0 alpha:1.0];
    [self.navigationController pushViewController:commentVC animated:YES];
}

- (void)setupBottomPayView {
    UIView *payView = [[UIView alloc]init];
    payView.backgroundColor = [UIColor whiteColor];
    payView.frame = CGRectMake(0, screenH - screenW / 375.0 * 60, screenW, screenW / 375.0 * 60);
    //价格的Label
    UILabel *priceLabel = [[UILabel alloc]init];
    priceLabel.text = [NSString stringWithFormat:@"¥ %@", self.data[@"price"]];
    priceLabel.font = [UIFont boldSystemFontOfSize:screenW / 375.0 * 22];
    priceLabel.textColor = [UIColor colorWithRed:0xfc /255.0 green:0x4a /255.0 blue:0x83 /255.0 alpha:1.0];
    
    [priceLabel sizeToFit];
    priceLabel.origin = CGPointMake(10, 6);
    [payView addSubview:priceLabel];
    
    //星级
    UIImageView *star1 = [[UIImageView alloc]init];
    UIImageView *star2 = [[UIImageView alloc]init];
    UIImageView *star3 = [[UIImageView alloc]init];
    UIImageView *star4 = [[UIImageView alloc]init];
    UIImageView *star5 = [[UIImageView alloc]init];
    
    star1.frame = CGRectMake(10, priceLabel.bottom, 15, 14);
    star2.frame = CGRectMake(star1.right + 5, priceLabel.bottom, 15, 14);
    star3.frame = CGRectMake(star2.right + 5, priceLabel.bottom, 15, 14);
    star4.frame = CGRectMake(star3.right + 5, priceLabel.bottom, 15, 14);
    star5.frame = CGRectMake(star4.right + 5, priceLabel.bottom, 15, 14);
    
    NSInteger star = [self.data[@"star_level"] integerValue];
    switch (star) {
        case 0:
        {
            star1.image = [UIImage imageNamed:@"star_n"];
            star2.image = [UIImage imageNamed:@"star_n"];
            star3.image = [UIImage imageNamed:@"star_n"];
            star4.image = [UIImage imageNamed:@"star_n"];
            star5.image = [UIImage imageNamed:@"star_n"];
        }
            break;
        case 1:
        {
            star1.image = [UIImage imageNamed:@"star_s"];
            star2.image = [UIImage imageNamed:@"star_n"];
            star3.image = [UIImage imageNamed:@"star_n"];
            star4.image = [UIImage imageNamed:@"star_n"];
            star5.image = [UIImage imageNamed:@"star_n"];
        }
            break;
        case 2:
        {
            star1.image = [UIImage imageNamed:@"star_s"];
            star2.image = [UIImage imageNamed:@"star_s"];
            star3.image = [UIImage imageNamed:@"star_n"];
            star4.image = [UIImage imageNamed:@"star_n"];
            star5.image = [UIImage imageNamed:@"star_n"];
        }
            break;
        case 3:
        {
            star1.image = [UIImage imageNamed:@"star_s"];
            star2.image = [UIImage imageNamed:@"star_s"];
            star3.image = [UIImage imageNamed:@"star_s"];
            star4.image = [UIImage imageNamed:@"star_n"];
            star5.image = [UIImage imageNamed:@"star_n"];
        }
            break;
        case 4:
        {
            star1.image = [UIImage imageNamed:@"star_s"];
            star2.image = [UIImage imageNamed:@"star_s"];
            star3.image = [UIImage imageNamed:@"star_s"];
            star4.image = [UIImage imageNamed:@"star_s"];
            star5.image = [UIImage imageNamed:@"star_n"];
        }
            break;
        case 5:
        {
            star1.image = [UIImage imageNamed:@"star_s"];
            star2.image = [UIImage imageNamed:@"star_s"];
            star3.image = [UIImage imageNamed:@"star_s"];
            star4.image = [UIImage imageNamed:@"star_s"];
            star5.image = [UIImage imageNamed:@"star_s"];
        }
            break;
        default:
            break;
    }
    
    [payView addSubview:star1];
    [payView addSubview:star2];
    [payView addSubview:star3];
    [payView addSubview:star4];
    [payView addSubview:star5];
    
    //联系客服
    UIButton *contactUsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    contactUsBtn.frame = CGRectMake(screenW / 375.0 * 150, 0, 100, payView.frame.size.height);
    [contactUsBtn setImage:[UIImage imageNamed:@"service"] forState:UIControlStateNormal];
    [contactUsBtn setTitle:@"联系客服" forState:UIControlStateNormal];
    [contactUsBtn setTitleColor:[UIColor colorWithRed:0x8d / 255.0 green:0xa5 / 255.0 blue:0xb8 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    [contactUsBtn.titleLabel setFont:[UIFont systemFontOfSize:12.0]];
    [contactUsBtn setImageEdgeInsets:UIEdgeInsetsMake(-25, 35, 0, 0)];
    [contactUsBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -15, -25, 0)];
    [contactUsBtn addTarget:self action:@selector(chatVC) forControlEvents:UIControlEventTouchUpInside];
    [payView addSubview:contactUsBtn];
    
    
    //预约按钮
    UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    payBtn.frame = CGRectMake(screenW - 110, 0, 110, payView.frame.size.height);
    [payBtn setTitle:@"预约拍摄" forState:UIControlStateNormal];
    [payBtn.titleLabel setFont:[UIFont systemFontOfSize:screenW / 375.0 * 16.0]];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payBtn.backgroundColor = [UIColor colorWithRed:0x76 /255.0 green:0xb1 /255.0 blue:0xfd /255.0 alpha:1.0];
    [payView addSubview:payBtn];
    
    //预约按钮的点击时间
    [payBtn addTarget:self action:@selector(payBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:payView];
}

- (void)chatVC {
    UIViewController *chatVC = [[UIViewController alloc]init];
    chatVC.title = @"在线客服";
    [self.navigationController pushViewController:chatVC animated:YES];
    
    UIWebView *webV = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, screenW, screenH)];
    [chatVC.view addSubview:webV];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://kefu.easemob.com/webim/im.html?tenantId=35180&hide=&sat=&resources=&ticket=true"]];
    [webV loadRequest:request];
}

- (void)payBtn {
    
    //拦截用户未登录状态
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"login"]) {
        for (UIButton *chooseBtn in self.chooseBtns) {
            if (chooseBtn.isSelected) {
                [SVProgressHUD showWithStatus:@"读取中..."];
                //获取套餐，摄影师和选择时间段的id
                NSString *combo_id = self.data[@"id"];
                NSDictionary *user = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
                AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
                mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                                 @"text/html",
                                                                 @"image/jpeg",
                                                                 @"image/png",
                                                                 @"application/octet-stream",
                                                                 @"text/json",
                                                                 nil];
                
                [mgr POST:[NSString stringWithFormat:@"%@?c=Order&&a=createOrder",requestURL]
               parameters:@{@"token" : user[@"token"],
                            @"packageID" : combo_id,
                            @"photographerID" : self.photographer_id,
                            @"timeId" : self.time_id}
                 progress:^(NSProgress * _Nonnull uploadProgress) {
                     
                 } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                     NSLog(@"预约拍摄 %@", responseObject);
                     if ([responseObject[@"state"] isEqualToString:@"SUCCESS"]) {
                         [SVProgressHUD dismiss];
                         BPPayViewController *payVC = [[BPPayViewController alloc]init];
                         payVC.data = responseObject[@"data"];
                         [self.navigationController pushViewController:payVC animated:YES];
                     }
                     else {
                         [SVProgressHUD showWithStatus:@"请求失败"];
                         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                             [SVProgressHUD dismiss];
                         });
                     }
                 } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                     [SVProgressHUD showWithStatus:@"网络故障"];
                     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                         [SVProgressHUD dismiss];
                     });
                 }];
                return;
            }
        }
    }
    else {
        [SVProgressHUD showInfoWithStatus:@"请先登录"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            return;
        });
    }
    
    //拦截没有选择摄影师的情况
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"需要选择一个摄影师" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:^{
    }];
}

#pragma mark - Photographer Protocol
// 摄影师界面数据逆传
- (void)selectedPhotographerID:(NSString *)photographerID timeID:(NSString *)timeID selectedDate:(NSString *)date selectedTime:(NSString *)time {
    self.photographer_id = photographerID;
    self.time_id = timeID;
    self.selectedDate = date;
    self.selectedTime = time;
    //获取所点摄影师cell的确认按钮
    for (UIView *view in self.selectedPhotographerCell.contentView.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *chooseBtn = (UIButton *)view;
            chooseBtn.backgroundColor = [UIColor colorWithRed:118/255.0 green:177/255.0 blue:253/255.0 alpha:1/1.0];
            chooseBtn.selected = YES;
            
            //获取预定的时间
            UILabel *label = [[UILabel alloc] init];
            label.text = [NSString stringWithFormat:@"%@ %@", self.selectedDate, self.selectedTime];
            label.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
            label.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
            label.tag = 99;
            label.backgroundColor = [UIColor whiteColor];
            [label sizeToFit];
            
            label.frame = CGRectMake(68, 80 - label.frame.size.height - 5, screenW - 68 - 20, label.frame.size.height);
            label.backgroundColor = [UIColor whiteColor];
            
            [self.selectedPhotographerCell addSubview:label];
            
        }
    }
}
@end
